package com.example.home.hospital.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import com.example.home.R;
import com.example.home.hospital.ExpertFragment;
import com.example.home.hospital.NormalFragment;
import com.example.home.hospital.adapter.RegistrPagerAdapter;
import com.example.home.hospital.bean.AllCardBean;
import com.example.home.hospital.bean.RegistrationBean;
import com.google.android.material.tabs.TabLayout;
import com.google.gson.Gson;


public class RegistrationMainActivity extends AppCompatActivity {

    private ImageView back;
    private ViewPager viewPager;
    public static RegistrationBean.RowsBean regisId1;
    public static AllCardBean.RowsBean regisId2;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_registration_main);
        initView();

        Intent intent = getIntent();
        if (intent != null) {
            String regisIdJson = intent.getStringExtra("regisId1");
            String regisId2Json = intent.getStringExtra("regisid2");

            Gson gson = new Gson();
            regisId1 = gson.fromJson(regisIdJson, RegistrationBean.RowsBean.class);
            regisId2 = gson.fromJson(regisId2Json, AllCardBean.RowsBean.class);

            // 在这里使用 regisId 和 regisId2 对象
        }
        getTabList();
    }

    private void getTabList() {
        TabLayout tabLayout = findViewById(R.id.tab_list);
        ViewPager viewPager = findViewById(R.id.viewPager);

        // 在这里创建 RegistrationBean.RowsBean 和 AllCardBean.RowsBean 的实例，然后传递给 NormalFragment
        RegistrationBean.RowsBean regisId1Instance = new RegistrationBean.RowsBean(/* 传递构造参数 */);
        AllCardBean.RowsBean regisId2Instance = new AllCardBean.RowsBean(/* 传递构造参数 */);

        // 创建 NormalFragment 的实例，并传递数据
        NormalFragment normalFragment = new NormalFragment(regisId1Instance, regisId2Instance);

        // 在使用FragmentManager添加Fragment
        RegistrPagerAdapter pagerAdapter = new RegistrPagerAdapter(getSupportFragmentManager());
        pagerAdapter.addFragment(new ExpertFragment(), "专家");
        pagerAdapter.addFragment(normalFragment, "普通");

        viewPager.setAdapter(pagerAdapter);
        tabLayout.setupWithViewPager(viewPager);
    }







    private void initView() {
        back = findViewById(R.id.back);
        viewPager = findViewById(R.id.viewPager);

        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RegistrationMainActivity.this.finish();
            }
        });
    }
}
